package net.cooltain.warhammer.running.window.command;

import java.awt.event.ActionEvent;

import javax.swing.JPanel;

import net.cooltain.utils.Logger;
import net.cooltain.warhammer.framework.constant.ConstantPhases;
import net.cooltain.warhammer.running.entity.MotionPlayerZone;

/**
 * 用户指令:[下一阶段]
 * @author cooltian
 *
 */
public class NextPhasesBtn extends UserCommandBtn {
	
	private static final long serialVersionUID = 1140481965412373942L;

	public NextPhasesBtn(MotionPlayerZone player) {
		super("下一阶段", player);
	}
	
	/**
	 * 判断当前时机是否可以显示这个按钮,如果允许则添加,如果不允许则不添加
	 * @param 要被放置的区域
	 */
	public void checkAndAddIn(JPanel userCmdPanel){
		if(this.player.isMyTurn){
			if( this.player.currentPhases==ConstantPhases.BEGENING_OF_TURN 
				|| this.player.currentPhases==ConstantPhases.KINGDOM_PHASES
				|| this.player.currentPhases==ConstantPhases.QUEST_PHASES
			    || this.player.currentPhases==ConstantPhases.CAPITAL_PHASES 
			    || ( this.player.currentPhases==ConstantPhases.BATTLEFIELD_PHASES 
		    		&&this.player.currentPhasesBattle==ConstantPhases.BATTLE6_CALC_DAMEGE) ){
				this.setEnabled(true);
				this.repaint();
				userCmdPanel.add(this);
				userCmdPanel.repaint();
			}
		}else{
			// do nothing
		}
	}

	@Override
	protected void command_actionPerformed(ActionEvent e) {
		Logger.info(this.player.playerName +" 执行了[下一阶段]指令");
		if(this.player.isMyTurn){
			int currentPhases = this.player.currentPhases;
			if( currentPhases==ConstantPhases.BEGENING_OF_TURN){
				this.player.toPhases1KingdomPhases();
			}else if( currentPhases==ConstantPhases.KINGDOM_PHASES){
				if(this.player.isFisrtPlay){
					this.player.toPhases3CapitalPhases();
				}else{
					this.player.toPhases2QuestPhases();					
				}
			}else if( currentPhases==ConstantPhases.QUEST_PHASES){
				this.player.toPhases3CapitalPhases();
			}else if( currentPhases==ConstantPhases.CAPITAL_PHASES){
				if(this.player.isFisrtPlay){
					this.player.toPhases5EndOfTurn();
				}else{
					this.player.toPhases4BattleFieldPhases();
				}
			}else if( this.player.currentPhases==ConstantPhases.BATTLEFIELD_PHASES 
		    		&&this.player.currentPhasesBattle==ConstantPhases.BATTLE6_CALC_DAMEGE) {
				this.player.toPhases5EndOfTurn();
			}
			this.setEnabled(false);
			this.player.mainFrame.clearUserCommand();
		}
	}

}
